const btn = document.querySelector('#btn-register')
btn.addEventListener('click', async function () {
  //   console.log(111)
  const form = document.querySelector('.register-form')
  const data = serialize(form, { hash: true, empty: true })
  //   console.log(deta)
  const { username, password } = data

  if (username.length < 8 || username.length > 30) {
    showToast('用户名8-30位')
    return
  }
  if (password.length < 6 || password.length > 30) {
    showToast('用户密码6-30位')
    return
  }
  try {
    const {
      data: { message }
    } = await axios.post('/register', data)
    //   console.log(res)
    //提示
    showToast(message)
  } catch (err) {
    showToast(err.response.data.message)
  }
})
